<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>有奖答题平台</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link rel="stylesheet" href="/lib/mobile/css/common.css"/>
    <link rel="stylesheet" href="/lib/mobile/css/answer.css"/>
    <link rel="stylesheet" href="/lib/mobile/css/analysis.css"/>
    <style>
        input{
            border: 0;
            text-align:center;
            width: 100px;
            border-bottom:1px solid #cccccc;
        }
    </style>
</head>
<body style="background-color: #f6f6f6;">

    <div class="top">
        <a href="javascript:void(0)" id="answer_back"><dl class="top_return"></dl></a>
        <!--<dl class="top_next"><a href="javascript:void(0)" id="answer_top">上一题</a></dl>-->
        <dl class="top_next"><a href="javascript:void(0)" id="answer_next">下一题</a></dl>

    </div>
    <div style="height: 56px;"></div>
    <div class="analysis_bg"></div>
    <div class="analysis_panel">
        <div class="main_title">
            <div class="title_left" id="qtype"></div>
            <div class="title_right">
                <span class="amount"><b id="index"></b>/<span id="cn"></span></span>
            </div>
        </div>
        <div class="analysis_subject">
            <div class="analysis_content" id="analysis_content">
            </div>
            <ul class="answer_choice" id="choice">
                <!--<li class="error"><i></i><span>侩炙人口</span></li>-->
                <!--<li class="success"><i></i><span>脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口脍炙人口</span></li>-->
            </ul>
        </div>
    </div>
    <div class="analysis_panel">
        <div class="main_title">
            <div class="title_left">答案解析</div>
        </div>
        <div class="analysis_subject">
            <div class="analysis_content" id="erroranswer"></div>
            <div class="analysis_content" id="correct"></div>
            <div class="analysis_text"><span style="color: #ff0000" id="resolve"></span></div>
        </div>
    </div>
    <ul class="bottom_menu">
        <li  id="indexsy"><a href="javascript:void(0);">首页</a></li>
        <!--<li>|</li>-->
        <li  id="hdrule"><a href="javascript:void(0);">活动规则</a></li>
        <!--<li  id="point_rule"><a href="javascript:void(0);">积分规则</a></li>-->
        <!--<li>|</li>-->
        <!--<li id="prize_rule"><a href="javascript:void(0);">抽奖规则</a></li>-->
        <!--<li>|</li>-->
        <li id="center"><a href="javascript:void(0);">个人中心</a></li>
    </ul>
    <!-- 依赖库 手机调试的js引用顺序如下 -->
    <script src="/lib/mobile/js/zepto.js"></script>
    <script src="/lib/mobile/js/plugins/fastclick.js"></script>
    <script src="/lib/mobile/js/bui.js"></script>
    <script src="/lib/mobile/js/common.js?66    "></script>
    <script>
        //答题题库数组
        var tkArr=[];
        //答题索引
        var indexflag=0;
        //答题ID
        var dtid;
        //题库ID
        var qid;
        //题型：多选题、单选题、判断题、填空题
        var qtype;
        //暂存的正确答案
        var rightanswer;
        bui.ready(function () {
            // 这里写业务及控件初始化
            var storage = bui.storage();
            var uid=storage.get("uid");
            var dtidArr=storage.get("dtid");
            dtid=dtidArr[0];
            // console.log(dtid);
            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();
            var pageview = {};
            pageview.init = function () {
                // 验证码示例
                $("#answer_next").on("click", function (argument) {
                    $("#index").html(indexflag+1);
                    if(indexflag+1==tkArr.length){
                        //当题库索引和数组长度一致时，答题结束
                        bui.load({ url: BASE_URL+"mobile/answer_finish"});
                    }else{
                        $("#answer_top").html("上一题");
                        indexflag++;
                        doHtml();
                    }
                });
                $("#answer_top").on("click", function (argument) {
                    if(indexflag==0){
                        $("#answer_top").html("已经是第一题");
                    }else if(indexflag>0){
                        indexflag--;
                        $("#index").html(indexflag+1);
                        doHtml();
                    }
                });
                $("#answer_back").on("click", function (argument) {

                    if(indexflag>0){
                        indexflag--;
                        $("#index").html(indexflag);
                        doHtml();
                    }
                });
                $("#indexsy").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/index"});
                });
                $("#point_rule").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/point_rule"});
                });
                $("#prize_rule").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/prize_rule"});
                });
                $("#center").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/center"});
                });
                getQuestionList(dtid);

            }
            pageview.init();
        });
        function getQuestionList(dtid) {
            //执行登录操作
            var loginAjax = bui.ajax({
                url: BASE_URL+"mobile/getQuestionList",
                // 可选参数
                data: {
                    dtid:dtid
                },
                method: "POST"
            });
            loginAjax.then(function(res) {
                if(res.code == 0){
                    var data = res.data;
                    tkArr=data.list;
                    doHtml();
                }else{
                    bui.alert(res.msg);
                }
            },function(res) {
                bui.alert("请求异常");
            })
        }
        function doHtml() {
            if(typeof(tkArr)!='undefined'){
                var content =tkArr[indexflag].QCONTENT;
                var correct =tkArr[indexflag].CORRECT;
                var resolve =tkArr[indexflag].RESOLVE;
                if(typeof(resolve)=="undefined"){
                    resolve='';
                }
                var doresult =tkArr[indexflag].doresult;
                if(typeof(doresult)=="undefined"){
                    doresult='';
                }
                // console.log(tkArr[indexflag]);
                // var reg = new RegExp("____","g");
                // var content= content.replace(reg,"<input type=\"text\" name=\"result\" value=\"\" placeholder=\"\" />");
                $("#analysis_content").html(content);
                $("#source").html('');
                $("#resolve").html(resolve);
                $("#index").html(indexflag+1);
                $("#cn").html(tkArr.length);
                qtype=tkArr[indexflag].QTYPE;
                qid=tkArr[indexflag].QID;
                $("#qtype").html(qtype);
                if(qtype=='填空题'){
                    $("#correct").html("正确答案: "+tkArr[indexflag].OPTIONA);
                    $("#choice").html("");
                    rightanswer = tkArr[indexflag].OPTIONA;
                }else{

                    $("#erroranswer").html("给出答案: "+doresult);
                    $("#correct").html("正确答案: "+correct);
                    var html='';
                    var aclass;
                    var bclass;
                    var cclass;
                    var dclass;
                    var eclass;
                    var fclass;
                    var gclass;
                    var hclass;

                    if(doresult==correct&&correct.indexOf('A')>=0){
                        aclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('A')<0&&correct.indexOf('A')>=0){
                        aclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('A')>=0&&correct.indexOf('A')<0){
                        aclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('A')>=0&&correct.indexOf('A')>=0){
                        aclass='success'
                    }
                    if(doresult==correct&&correct.indexOf('B')>=0){
                        bclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('B')<0&&correct.indexOf('B')>=0){
                        bclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('B')>=0&&correct.indexOf('B')<0){
                        bclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('B')>=0&&correct.indexOf('B')>=0){
                        bclass='success'
                    }

                    if(doresult==correct&&correct.indexOf('C')>=0){
                        cclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('C')<0&&correct.indexOf('C')>=0){
                        cclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('C')>=0&&correct.indexOf('C')<0){
                        cclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('C')>=0&&correct.indexOf('C')>=0){
                        cclass='success'
                    }
                    if(doresult==correct&&correct.indexOf('D')>=0){
                        dclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('D')<0&&correct.indexOf('D')>=0){
                        dclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('D')>=0&&correct.indexOf('D')<0){
                        dclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('D')>=0&&correct.indexOf('D')>=0){
                        dclass='success'
                    }
                    if(doresult==correct&&correct.indexOf('E')>=0){
                        eclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('E')<0&&correct.indexOf('E')>=0){
                        eclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('E')>=0&&correct.indexOf('E')<0){
                        eclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('E')>=0&&correct.indexOf('E')>=0){
                        eclass='success'
                    }
                    if(doresult==correct&&correct.indexOf('F')>=0){
                        fclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('F')<0&&correct.indexOf('F')>=0){
                        fclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('F')>=0&&correct.indexOf('F')<0){
                        fclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('F')>=0&&correct.indexOf('F')>=0){
                        fclass='success'
                    }
                    if(doresult==correct&&correct.indexOf('G')>=0){
                        gclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('G')<0&&correct.indexOf('G')>=0){
                        gclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('G')>=0&&correct.indexOf('G')<0){
                        gclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('G')>=0&&correct.indexOf('G')>=0){
                        gclass='success'
                    }
                    if(doresult==correct&&correct.indexOf('H')>=0){
                        hclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('H')<0&&correct.indexOf('H')>=0){
                        hclass='success'
                    }else if(doresult!=correct&&doresult.indexOf('H')>=0&&correct.indexOf('H')<0){
                        hclass='error'
                    }else if(doresult!=correct&&doresult.indexOf('H')>=0&&correct.indexOf('H')>=0){
                        hclass='success'
                    }
                    // console.log(tkArr[indexflag].OPTIOND);
                    if(tkArr[indexflag].OPTIONA){
                        html = html + "<li class=\""+aclass+"\"><i>A</i><span>" + tkArr[indexflag].OPTIONA + "</span></li>";

                    }
                    if(tkArr[indexflag].OPTIONB){
                        html = html + "<li class=\""+bclass+"\"><i>B</i><span>" + tkArr[indexflag].OPTIONB + "</span></li>";

                    }
                    if(tkArr[indexflag].OPTIONC){
                        html = html + "<li class=\""+cclass+"\"><i>C</i><span>" + tkArr[indexflag].OPTIONC + "</span></li>";
                    }
                    if(tkArr[indexflag].OPTIOND){
                        html = html + "<li class=\""+dclass+"\"><i>D</i><span>" + tkArr[indexflag].OPTIOND + "</span></li>"
                    }
                    if(tkArr[indexflag].OPTIONE){
                        html = html + "<li class=\""+eclass+"\"><i>E</i><span>" + tkArr[indexflag].OPTIONE + "</span></li>"
                    }
                    if(tkArr[indexflag].OPTIONF){
                        html = html + "<li class=\""+fclass+"\"><i>F</i><span>" + tkArr[indexflag].OPTIONF + "</span></li>"
                    }
                    if(tkArr[indexflag].OPTIONG){
                        html = html + "<li class=\""+gclass+"\"><i>G</i><span>" + tkArr[indexflag].OPTIONG + "</span></li>"
                    }
                    if(tkArr[indexflag].OPTIONH){
                        html = html + "<li class=\""+hclass+"\"><i>H</i><span>" + tkArr[indexflag].OPTIONH + "</span></li>"
                    }
                    $("#choice").html(html);
                }
            }
        }
        var res='';
        function dealAnswer() {
            var retVal='';
            var arr=[];
            if(qtype=='填空题'){
                var doresultObj = $("input[name='result']");
                var i=0;
                $("input[name='result']").each(
                    function(){
                        arr.push($(this).val());
                        retVal=arr.join("|");
                    }
                )
            }else{
                retVal=res;
            }
            return retVal;
        }
        Array.prototype.indexOf = function(val) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == val) return i;
            }
            return -1;
        };
        Array.prototype.remove = function(val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
    </script>
</body>
</html>